<?php
namespace App\Servers\Backend;

use App\Repositories\Backend\EnvironmentRepository;

class EnvironmentServer extends CommonServer
{

    public function __construct(
        EnvironmentRepository $environmentRepository
    ) {
        $this->environmentRepository = $environmentRepository;
    }

    /**
     * 列表
     * @param  Array $input [search]
     * @return Array
     */
    public function index($input)
    {
        $result['lists']   = $this->environmentRepository->getLists($input);
        return ['获取成功', $result];
    }

    /**
     * 新增
     * @param  Array $input [subject_id, doctor_name, face_image, tags, easy_adepts, detail_adepts, consult_number, registration_number, order]
     * @return Array
     */
    public function create($input)
    {
        $environments_image  = isset($input['environments_image']) ? strval($input['environments_image']) : '';
        $environments_title  = isset($input['environments_title']) ? strval($input['environments_title']) : '';
        $order               = isset($input['order']) ? intval($input['order']) : '';


        if (!$environments_image || !$environments_title || !$order ) {
            return ['code' => ['x00004', 'system']];
        }

        $result['list'] = $this->environmentRepository->create($environments_image, $environments_title, $order);

        if (!$result['list']) {
            return ['code' => ['x00001', 'system']];
        }

        return ['新增成功', $result];
    }


    /**
     * 删除
     * @param  Int $id
     * @return Array
     */
    public function destroy($id)
    {
        $result = $this->environmentRepository->destroy($id);

        if (!$result) {
            return ['code' => ['x00002', 'system']];
        }

        return ['删除成功', $result];
    }
}
